package com.newyear.concertManagementSystem.service.impl;

import dao.ConcertDao;
import entity.Concert;
import org.apache.ibatis.session.SqlSession;
import com.newyear.concertManagementSystem.service.ConcertService;
import utils.MyBatisUtil;

import java.util.List;

public class ConcertServiceImpl implements ConcertService {

    @Override
    public List<Concert> page(int startIndex, int pageSize) {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        return sqlSession.getMapper(ConcertDao.class).page(startIndex,pageSize);
    }

    @Override
    public int count() {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        return sqlSession.getMapper(ConcertDao.class).count();
    }

    @Override
    public int repeat(String concertName) {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        return sqlSession.getMapper(ConcertDao.class).repeat(concertName);
    }

    @Override
    public int add(Concert concert) {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        int add = sqlSession.getMapper(ConcertDao.class).add(concert);
        sqlSession.commit();
        return add;
    }
}
